package com.san.app.dao;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.alibaba.druid.pool.DruidPooledConnection;
import com.san.base.dao.BaseManager;
import com.san.common.datasource.JdbcManager;
import com.san.common.utils.Constant;
import com.san.metadata.domain.DataSourceDO;

@Service
public class InspectManager extends BaseManager{

	/**
	 * 执行核查sql语句
	 * @param sql
	 * @param obj
	 * @param dataSourceDO
	 * @return
	 */
	public List getCheckResult(int inspectType,List<String> data,String sql,Object[] obj,DataSourceDO dataSourceDO){
		DruidPooledConnection conn = null;
		List<Map<String, Object>> list = null;
		try {
			conn = this.getDBConnection(dataSourceDO.getSourceCode());
			JdbcManager jdbcManager = new JdbcManager();
			if(inspectType == Constant.MANAGE_DATA_TYPE_LEGAL_PERSON){//法人
				list = jdbcManager.executeQuery(conn,sql, obj);
				for (Map<String, Object> map : list) {
					if(map != null && map.size() > 0){
						map.put("legal_person_name",data.get(0));
					}
				}
			}else if(inspectType == Constant.MANAGE_DATA_TYPE_NATURAL_PERSON){//自然人
				list = jdbcManager.executeQuery(conn,sql, obj);
				for (Map<String, Object> map : list) {
					if(map != null && map.size() > 0){
						map.put("natural_person_name",data.get(0));
					}
				}
			}else if(inspectType == Constant.MANAGE_DATA_TYPE_LEGAL_PERSON_OR_NATURAL_PERSON){//法人或自然人
				list = jdbcManager.executeQuery(conn, sql, obj);
				for (Map<String, Object> map : list) {
					if(map != null && map.size() > 0){
						map.put("legal_or_natural_name",data.get(0));
					}
				}
				
			}else if(inspectType == Constant.MANAGE_DATA_TYPE_LEGAL_PERSON_AND_NATURAL_PERSON){//法人和自然人
				list = jdbcManager.executeQuery(conn,sql, obj);
				for (Map<String, Object> map : list) {
					if(map != null && map.size() > 0){
						map.put("legal_person_name",data.get(0));
						map.put("natural_person_name",data.get(2));
					}
				}
			}else if(inspectType == Constant.MANAGE_DATA_TYPE_NATURAL_PERSON_OR_NATURAL_PERSON){//自然人和自然人
				list = jdbcManager.executeQuery(conn,sql, obj);
				for (Map<String, Object> map : list) {
					if(map != null && map.size() > 0){
						map.put("legal_person_name",data.get(0));
						map.put("natural_person_name",data.get(2));
					}
				}
			}
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
}
